package com.dona.imsidetector.db.entity;


import com.dona.imsidetector.utils.DeviceUtil;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import org.xutils.db.annotation.Column;
import org.xutils.db.annotation.Table;

import java.util.Set;

@Table(name = "history")
public class History {

    @Column(name = "uuid", isId = true)
    private String uuid;


    // 运营商 1表示移动， 2表示联通 3表示电信 4表示未知
    @Column(name = "isp")
    private Integer isp;

    // 设备1和2
    @Column(name = "deviceId")
    private Integer deviceId;

    @Column(name = "freqs")
    private String freqs;

    public History(Integer isp, Integer deviceId, Set<Integer> freqs) {
        this.uuid = DeviceUtil.getUUID();
        this.isp = isp;
        this.deviceId = deviceId;
        this.freqs = freqsToJson(freqs);
    }

    public History() {
    }

    public Integer getIsp() {
        return isp;
    }

    public void setIsp(Integer isp) {
        this.isp = isp;
    }

    public Integer getDeviceId() {
        return deviceId;
    }

    public void setDeviceId(Integer deviceId) {
        this.deviceId = deviceId;
    }

    public String getFreqs() {
        return freqs;
    }

    public void setFreqs(String freqs) {
        this.freqs = freqs;
    }

    public static String freqsToJson(Set<Integer> selected) {
        Gson gson = new Gson();

        String toJson = gson.toJson(selected);


        return toJson;
    }

    public static Set<Integer> freqsFromJson(String json) {
        Gson gson = new Gson();

        return gson.fromJson(json, new TypeToken<Set<Integer>>() {
        }.getType());
    }

    @Override
    public String toString() {
        return "History{" +
                "uuid='" + uuid + '\'' +
                ", isp=" + isp +
                ", deviceId=" + deviceId +
                ", freqs='" + freqs + '\'' +
                '}';
    }
}
